package demo.pattern.proxy.jdkProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @ClassName AlipayJdkProxy
 * @Description
 * @Author 47980
 * @Date 2020/8/9 15:45
 * @Version V_1.0
 **/
public class AlipayInvocationHandler implements InvocationHandler {

    private Object targetObjcet;

    public AlipayInvocationHandler(Object targetObjcet) {
        this.targetObjcet = targetObjcet;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        beforePay();
        Object result = method.invoke(targetObjcet, objects);
        afterPay();
        return result;
    }

    private void beforePay() {
        System.out.println("从招行里取款");
    }

    private void afterPay() {
        System.out.println("支付给XXX");
    }
}
